package com.ruyuan.seckilling.common;

import java.util.Collections;
import java.util.LinkedHashMap;

/**
 * <pre>
 * 通用的返回结果
 * 有2个基础字段
 * 1、success 表示是否成功
 * 2、info 表示错误时的提示信息
 * 3、data 数据
 * 其他具体的字段由用户自己指定
 * </pre>
 *
 * @author zhonghuashishan
 */
public class MapResult extends LinkedHashMap<String, Object> {
    private static final long serialVersionUID = -8947377654306672461L;

    public static MapResult successResult() {
        return new MapResult().setSuccess(true);
    }

    public static MapResult errorResult() {
        return new MapResult().setSuccess(false);
    }

    public MapResult setSuccess(Boolean success) {
        put("success", success);
        return this;
    }

    public MapResult setInfo(String info) {
        put("info", info);
        return this;
    }

    public MapResult setDataList(Object data) {
        put("dataList", data);
        return this;
    }

    public MapResult setEmptyDataList() {
        put("dataList", Collections.emptyList());
        return this;
    }

    public MapResult set(String k, Object v) {
        put(k, v);
        return this;
    }
}
